﻿<button type="button" class="btn btn-success" id="GetByFromQuery">GetByFromQuery</button>
<script type="text/javascript">
    $(() => {
        $("#GetByFromQuery").click(function () {
            let button = this;
            $.ajax({
                url: '/api/HttpVerb/GetByFromQuery',
                data: {
                    name: 'Jone',
                    age: '18'
                },
                dataType: 'json',
                beforeSend: function (xhr) {
                    xhr.setRequestHeader('appkey', 'appkey12345');
                    xhr.setRequestHeader('appsecret', 'appsecrte12345');
                    $(button).attr({ disabled: "disabled" });
                },
                method: 'GET',
                headers: {
                    'sign': "asdfasdfasd"
                },
                success: function (data) {
                    console.log(JSON.stringify(data));
                },
                complete: function () {
                    $(button).removeAttr('disabled');
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    console.log(JSON.stringify(jqXHR.responseJSON), textStatus, errorThrown);
                }
            });
        });
    });
</script>


<button type="button" class="btn btn-success" id="PostByFormQuery">PostByFormQuery</button>
<script type="text/javascript">
    $(() => {
        $("#PostByFormQuery").click(function () {
            let button = this;
            $.ajax({
                url: '/api/HttpVerb/PostByFormQuery?name=name&age=age',
                dataType: 'json',
                beforeSend: function (jqXHR, settings) {
                    jqXHR.setRequestHeader('appkey', 'appkey12345');
                    jqXHR.setRequestHeader('appsecret', 'appsecrte12345');
                    $(button).attr({ disabled: "disabled" });
                },
                method: 'POST',
                headers: {
                    'sign': "asdfasdfasd"
                },
                success: function (data, textStatus, jqXHR) {
                    console.log(JSON.stringify(data));
                },
                complete: function () {
                    $(button).removeAttr('disabled');
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    console.log(JSON.stringify(jqXHR.responseJSON), textStatus, errorThrown);
                }
            });
        });
    });
</script>



<button type="button" class="btn btn-success" id="PutByFormQuery">PutByFormQuery</button>
<script type="text/javascript">
    $(() => {
        $("#PutByFormQuery").click(function () {
            let button = this;
            $.ajax({
                url: '/api/HttpVerb/PutByFormQuery?id=15',
                data: {
                    name: 'tom',
                    age: '15',
                    '': "{\"no\":\"123456\"}"
                },
                dataType: 'json',
                beforeSend: function (xhr) {
                    xhr.setRequestHeader('appkey', 'appkey12345');
                    xhr.setRequestHeader('appsecret', 'appsecrte12345');
                    $(button).attr({ disabled: "disabled" });
                },
                method: 'PUT',
                success: function (data) {
                    console.log(JSON.stringify(data));
                },
                complete: function () {
                    $(button).removeAttr('disabled');
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    console.log(JSON.stringify(jqXHR.responseJSON), textStatus, errorThrown);
                }
            });
        });
    });
</script>


<button type="button" class="btn btn-success" id="FromForm1">FromForm1</button>
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.2.1.min.js"></script>
<script>
    $(document).ready(function () {
        $("button").click(function (e) {

            data = new FormData();
            data.append("age", 5);
            data.append("name", "Donald Trump");

            $.ajax({
                url: "/api/From/FromForm1",
                method: "post",
                /** Jquery使用FormData传输关键点 */
                processData: false,/** 不处理发送的数据*/
                contentType: false,/** 不使用类型*/

                data: data,
                success: function (data) {
                    $("#empId").text(data.id);
                    $("#empName").text(data.name);
                }
            });
        });
    });
</script>